const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const StudentProgress = sequelize.define('StudentProgress', {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    primaryKey: true
  },
  userId: {
    type: DataTypes.STRING(50),
    allowNull: false,
    references: {
      model: 'users',
      key: 'id'
    }
  },
  courseId: {
    type: DataTypes.STRING(50),
    allowNull: true,
    references: {
      model: 'courses',
      key: 'id'
    }
  },
  chapterId: {
    type: DataTypes.STRING(255),
    allowNull: true
  },
  lessonId: {
    type: DataTypes.STRING(255),
    allowNull: true
  },
  actionType: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: 'e.g., view_video, complete_assignment, view_lecture'
  },
  timestamp: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  details: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: 'Additional details about the action, e.g., video progress, assignment score'
  }
}, {
  tableName: 'student_progress',
  timestamps: true
});

module.exports = StudentProgress;